import { $get, $put } from '@js/request'
import { ServiceTopicSchema } from '@src/components/schema/service'
import moment from 'moment'

// 获取送达表格数据
export async function getDefaultDate (topicid: string) {
  const res = await $get('/api/commission/deliver/getMaxDeliverTime', {
    topicid
  })
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  const t = res.data
  if (t) {
    return moment(t * 1000)
  }
  return undefined
}

// 送达主题完成请求
export async function finishRequest (data: {[k: string]: any}, theme: ServiceTopicSchema) {
  const res = await $put(`/api/commission/delivertopic/${theme.id}`, {
    ...data
  })
  if (res.status !== 1) {
    throw new Error(res.message)
  }
  return res.data
}
